let setHtmlFont = () => {
  // 限定 html 的字体比例，其他内容尺寸根据 html 的大小进行限定
  // 以iPhone p时，100px 为基准
  //! 最大宽度 414
  let windowW = window.innerWidth ? window.innerWidth : document.body.clientWidth
  let windowH = window.innerHeight ? window.innerHeight : document.body.clientHeight
  let rootEle = document.querySelector('#root')
  if (IsPC()) {
    if (rootEle) {
      rootEle.style.maxWidth = '800px'
      rootEle.style.margin = '0 auto'
      rootEle.style.overflow = 'auto'
    }
    if (windowW > 414) {
      windowW = 414
    }
    let scale = windowW / 750
    let winFont = 100 * scale
    document.documentElement.style.fontSize = winFont + 'px'
  } else {
    let scale = windowW / 750
    let winFont = 100 * scale
    document.documentElement.style.fontSize = winFont + 'px'
  }
  if (rootEle) {
    rootEle.style.height = windowH + 'px'
  }
}
setHtmlFont()
window.addEventListener('resize', () => {
  setHtmlFont()
  setInputIntoView()
}, false)


// 节流
let inputViewId = true
function setInputIntoView() {
  if (!inputViewId) return
  const u = navigator.userAgent
  if (!(u.indexOf('Android') > -1 || u.indexOf('Linux') > -1)) return
  inputViewId = false
  setTimeout(() => {
    inputViewId = true
    let inputDom = document.querySelectorAll('input:focus')[0]
    if (inputDom) {
      inputDom.scrollIntoView(false)
      inputDom.scrollIntoViewIfNeeded(true)
    }
  }, 240)
}

function IsPC() {
  var userAgentInfo = navigator.userAgent;
  var Agents = ['Android', 'iPhone',
    'SymbianOS', 'Windows Phone',
    'iPad', 'iPod'
  ];
  var flag = true;
  for (var i = 0; i < Agents.length; i++) {
    if (userAgentInfo.indexOf(Agents[i]) != -1) {
      flag = false;
      break;
    }
  }
  return flag;
}
